#include "system.h"
#include <plib.h>
#include "delay.h"

void DelayMs(WORD delay)
 {
     unsigned int int_status;
     while( delay--)
     {
         int_status = INTDisableInterrupts();
         OpenCoreTimer(GetSystemClock() / 1000);
         INTRestoreInterrupts(int_status);
         mCTClearIntFlag();

         while( !mCTGetIntFlag() );
     }
     mCTClearIntFlag();
 }

void DelayUs(WORD delay)
 {
     unsigned int int_status;
     while(delay--)
     {
         int_status = INTDisableInterrupts();
         OpenCoreTimer(GetSystemClock() / 1000000);
         INTRestoreInterrupts(int_status);
         mCTClearIntFlag();

         while( !mCTGetIntFlag() );
     }
     mCTClearIntFlag();
 }